package com.dm.cloud.images.mapper;

import com.dm.cloud.images.common.mode.ImagesAppArrangeExtend;
import com.dm.cloud.tkmybatis.service.BaseMapper;
import com.dm.cloud.images.common.po.ImagesAppArrange;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
   * @author hcx
   * @type ImagesAppArrangeMapper.java
   * @desc ImagesAppArrange mapper
   */

@Mapper
public interface ImagesAppArrangeMapper extends BaseMapper<ImagesAppArrange> {

    @Delete("delete from T_IMAGES_APP_ARRANGE where container_id=#{containerId} and node_id=#{nodeId}")
    int deleteByNodeIdAndImagesId(@Param("containerId") String containerId,@Param("nodeId") String nodeId);

    @Delete("delete from T_IMAGES_APP_ARRANGE where app_code=#{appCode}")
    int deleteByAppCode(@Param("appCode") String appCode);

    @Select("select * from T_IMAGES_APP_ARRANGE where app_code=#{appCode} order by step,step_index")
    List<ImagesAppArrange> findByAppCode(@Param("appCode") String appCode);

    @Select("select a.id,a.create_time createTime,a.update_time updateTime,a.create_user createUser,a.update_user updateUser,a.app_code appCode,a.success_condition successCondition,a.step,a.step_index stepIndex,a.container_id containerId,a.node_id nodeId,a.timeout," +
            "c.status operateStatus,c.result containerResult,c.task_id taskId,c.err_str errStr " +
            "from " +
            "t_images_app_arrange a " +
            "left join (select s.*,d.app_code from t_images_app_task_container s INNER JOIN t_images_app_task d on d.id=s.task_id) c on c.node_id=a.node_id and c.container_id=a.container_id and c.app_code=a.app_code  " +
            "where a.app_code=#{appCode} order by step,step_index")
    List<ImagesAppArrangeExtend> findAppStatus(@Param("appCode") String appCode);


}
